<%@page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<jsp:useBean id="user" class="model.User" scope="session" />
<jsp:useBean id="povl" class="model.Povlastica" scope="session" />

<html>
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Izmena povlastice</title>
</head>
<body>
<h1>Izmena povlastice</h1>

<%
	if (user != null && user.isLoggedIn()) {
%>
<form action="/admin" method="get">
<table>
	<tr>
		<td align=right>Naziv:</td>
		<td><input type="text" name="naziv" value="${povl.naziv}"></td>
	</tr>
	<tr>
		<td align=right>Tip:</td>
		<td><select name="op" size="2">
			<option value="1"
				<%= povl.getOp() == 1 ? "selected = \"true\"" : ""%>>Procenat</option>
			<option value="2"
				<%= povl.getOp() == 2 ? "selected = \"true\"" : ""%>>Iznos</option>
		</select></td>
	</tr>
	<tr>
		<td align=right>Iznos:</td>
		<td><input type="text" name="vrednost" value="${povl.vrednost}"></td>
	</tr>
	<tr>
		<td align=right>Kategorija: <br>
		(Izaberite jednu )</td>
		<td><select name="kat" size="5">
			<c:forEach var="benCat" items="${sessionScope.allBenCats}">
				<c:set var="readCatID">${benCat.sifra.id}</c:set>
				<% 
			   String ID1 = (String)pageContext.getAttribute("readCatID");
			   String ID2 = povl.getKatPovlastice().getSifra().getId() + "";
			   
			   if(!ID1.equals(ID2)){ %>
				<option value="${benCat.sifra.id}">${benCat.naziv}</option>
				<%}else{ %>
				<option selected="selected" value="${benCat.sifra.id}">${benCat.naziv}</option>
				<%} %>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td><input type="hidden" name="changedBenefit" value="true">
		<input type="hidden" name="ID" value="${povl.sifra.id}"></td>
		<td><input type="submit" value="Izmeni"></td>
	</tr>
</table>

</form>
<%
	} else {
%>
<p>Niste se prijavili! <br>
<a href="/logIn">Prijavi se</a></p>
<%
	}
%>

<p><a href="/admin">Red voznje</a> <br>
<a href="/logIn?logOff=true">Odjava</a></p>

</body>
</html>
